//
// Created by mnutec on 2021/2/3.
//

#include "Sphere.h"
namespace GLM {
    const float PI= 3.14159265358979323846f;
    GLM::Sphere::Sphere():model() {
        for (int y = 0; y <= Y_SEGMENTS; y++) {
            for (int x = 0; x <= X_SEGMENTS; x++) {
                float xSegment = (float) x / (float) X_SEGMENTS;
                float ySegment = (float) y / (float) Y_SEGMENTS;
                float xPos = cos(xSegment * 2.0f * PI) * sin(ySegment * PI);
                float yPos = sin(xSegment * 2.0f * PI) * sin(ySegment * PI);
                float zPos = cos(ySegment * PI);
                mesh.push_back({{xPos,yPos,zPos,1.0},{xSegment,ySegment},{1.0f,xPos, yPos, zPos},1});

            }
        }



        //生成球的Indices
        for (int i = 0; i < Y_SEGMENTS; i++) {
            for (int j = 0; j < X_SEGMENTS; j++) {
                indices.push_back({i * (X_SEGMENTS + 1) + j,(i + 1) * (X_SEGMENTS + 1) + j,(i + 1) * (X_SEGMENTS + 1) + j+1,i * (X_SEGMENTS + 1) + j + 1});

            }
        }

    }

}